//方法一：线性查找
int findTheDistanceValue(int* arr1, int arr1Size, int* arr2, int arr2Size, int d) {
    int count = 0;
    for(int i = 0; i < arr1Size; i++){
        for(int j = 0; j < arr2Size; j++){
            if(abs(arr1[i] - arr2[j]) > d)
                continue;
            else{
                count -= 1;
                break;
            }
        }
        count++;
    }
    return count;
}

//方法二：二分查找
int cmp(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int findTheDistanceValue(int* arr1, int arr1Size, int* arr2, int arr2Size, int d) {
    qsort(arr2, arr2Size, sizeof(int), cmp);
    int count = 0;
    for(int i = 0; i < arr1Size; i++){
        int left = 0, right = arr2Size - 1;
        while(left <= right){
            int mid = left + (right - left)/2;
            if(arr1[i] > arr2[mid]){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        if(left < arr2Size && abs(arr1[i] - arr2[left]) > d)
            if(right >= 0 && abs(arr1[i] - arr2[right]) > d)
                count++;
        if(left == arr2Size && arr2[left - 1] < arr1[i] - d)
            count++;
        if(right == -1 && arr2[right + 1] > arr1[i] + d)
            count++;
    }
    return count;
}

/*给你两个整数数组arr1，arr2和一个整数d，请你返回两个数组之间的距离值。

「距离值」定义为符合此距离要求的元素数目：对于元素arr1[i]，不存在任何元素arr2[j]满足|arr1[i]-arr2[j]|<= d 。*/